package com.sskj.gocoin.v.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.sskj.common.base.App;
import com.sskj.gocoin.R;
import com.sskj.gocoin.R2;
import com.sskj.gocoin.common.widget.ToolBarLayout;
import com.sskj.gocoin.component.DaggerUserDataComponent;
import com.sskj.gocoin.p.activity.VerifyResultActivityPresenter;
import com.sskj.gocoin.utils.ClickUtil;
import com.sskj.gocoin.v.base.BaseActivity;
import com.sskj.lib.RConfig;
import com.sskj.lib.bean.UserData;
import com.sskj.lib.model.room.UserViewModel;

import javax.inject.Inject;

import butterknife.BindView;

@Route(path = RConfig.MINE_VERIFY_RESULT)
public class VerifyResultActivity extends BaseActivity<VerifyResultActivityPresenter> {
    @BindView(R2.id.verify_status)
    TextView verifyStatus;
    @BindView(R2.id.failed_reason)
    TextView failedReason;
    @BindView(R2.id.reset_verify)
    TextView resetVerify;
    @BindView(R2.id.verify_failed_rl)
    LinearLayout verifyFailedRl;
    @BindView(R2.id.ll_verify_status)
    LinearLayout ll_verify_status;
    @BindView(R2.id.toolbar)
    ToolBarLayout toolBar;
    @Autowired
    public boolean isSuccess;  // true 认证成功
    @Inject
    UserViewModel userViewModel;
    private UserData userData;


    @Override
    protected int getLayoutResId() {
        return R.layout.activity_verify_result;
    }

    @Override
    public VerifyResultActivityPresenter getPresenter() {
        return new VerifyResultActivityPresenter();
    }

    @Override
    protected void initView() {
        ARouter.getInstance().inject(this);
        toolBar.setLeftButtonOnClickLinster(v -> finish());
        toolBar.setTitle(isSuccess ? App.INSTANCE.getString(R.string.strCommonActivity200) : App.INSTANCE.getString(R.string.fabimineJavaVerifyHomeActivity3));
        toolBar.setLeftButtonOnClickLinster(v -> finish());
        DaggerUserDataComponent.create().inject(this);
        userViewModel.getUsers().observe(this, users -> {
            if (users != null && users.size() > 0) {
                userData = users.get(0);
                if (!isSuccess) {
                    failedReason.setText(App.INSTANCE.getString(R.string.fabi_shensu_fail_reason) + userData.getApply_reason());
                }
            } else {
                userData = null;
            }
        });
        if (isSuccess) {
            ll_verify_status.setVisibility(View.VISIBLE);
            verifyFailedRl.setVisibility(View.GONE);
        } else {
            ll_verify_status.setVisibility(View.GONE);
            verifyFailedRl.setVisibility(View.VISIBLE);
        }

        ClickUtil.click(resetVerify, () -> {
            VerifyGuideActivity.start(this);
            finish();
        });
    }

    @Override
    protected void initData() {

    }

    // 失败原因
    public void updateUi(String data) {
        failedReason.setText(App.INSTANCE.getString(R.string.fabi_shensu_fail_reason) + data);
    }

}
